#ifndef QABSTRACTPROPERTY_H
#define QABSTRACTPROPERTY_H

#include "property_global.h"

#include "qpropertyfactory.h"

#include <QObject>
#include <QMap>
#include <QVariant>
#include <QIcon>


#define PROPERTY_TITLE "Property"



#define ATTR_EDITABLE "Editable"
#define ATTR_NEEDSAVE "Need_Save"
#define ATTR_VISIBLE  "Visible"
#define ATTR_CAN_SAME "Can_Same"
#define ATTR_RESET_ABLEABLE "Can_Reset"
#define ATTR_NEED_UPDATE    "Need_Update"

class XMLObject;
class QAbstractHost;

class PROPERTY_SHARED_EXPORT QAbstractProperty : public QObject
{
    Q_OBJECT
public:
    explicit QAbstractProperty(QAbstractProperty *parent = 0);
    ~QAbstractProperty();

    virtual void    set_value(const QVariant& value);
    virtual QVariant get_value();
    void            reset();
    virtual QString get_value_text()=0;
    virtual QIcon   get_value_icon()=0;

    void            set_default();

    bool            modified();

    virtual void    toObject(XMLObject* xml);
    virtual void    fromObject(XMLObject* xml);

    void            set_attribute(const QString &key,const QVariant& value);
    QVariant        get_attribute(const QString &key);

    void            set_property(const QString &key,const QVariant& value);
    QVariant        get_property(const QString &key);


    QAbstractProperty& operator =(const QAbstractProperty &pro);

    QList<QAbstractProperty*> get_children();
    QAbstractProperty        *get_parent();
    QAbstractProperty        *get_child(const QString &name);

    void emit_edit_value(const QVariant& value);

    void    set_host(QAbstractHost* host);
    QAbstractHost* get_host();
protected slots:
    virtual void    child_value_changed(const QVariant& old,const QVariant &now);
protected:
    void    connect_children();
    void    disconnect_children();
    virtual void    make_value();
    virtual void    write_value();
signals:
    void    value_chaged(const QVariant& old,const QVariant &now);
    void    refresh();
    void    edit_value(const QVariant &value);
public slots:
protected:
    QAbstractProperty*          m_parent;
    QList<QAbstractProperty*>   m_children;
    QMap<QString,QVariant>      m_attributes;
    QMap<QString,QVariant>      m_propertys;
    QVariant                    m_value;
    QVariant                    m_defaultValue;
    QAbstractHost               *m_host;
};

#endif // QABSTRACTPROPERTY_H
